package Thread.Thread6;

import java.util.List;
import java.util.Random;

public class SendThraed extends Thread{
    private List<String> gift;

    private int count;



    public SendThraed(List<String> gift, String name) {
        super(name);
        this.gift = gift;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        Random r = new Random();
        //发礼物出去
        //实现线程安全问题
        //注意： 锁必须唯一
        while (true){
            synchronized (gift){
                if (gift.size()<10){
                    break;
                }
                String s = gift.remove(r.nextInt(gift.size()));
                System.out.println(name+"发出了"+s);
                count++;

            }
        }



    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
